package com.gitee.wsl.struct.tree.builder

import com.gitee.wsl.struct.tree.sample.link.LinkTreeElement

class ChildrenGeneratorScope<T>(private val parentElement: LinkTreeElement.Node<T>) :
    TreeGeneratorScope<T> {
     class ParentInfo<T>( val data: T,  val depth: Int,  val index: Int)

    val parent: ParentInfo<T> by lazy {
       ParentInfo(parentElement.data, parentElement.depth, parentElement.childIndex)
   }

   internal val elements = mutableListOf<LinkTreeBuilder.Element<T>>()

   override fun addLeaf(data: T, id: Any?) {
       elements.add(LinkTreeBuilder.Element.Leaf(data, id))
   }

   override fun addNode(data: T, id: Any?, childrenGenerator: ChildrenGeneratorScope<T>.() -> Unit) {
       elements.add(LinkTreeBuilder.Element.Node(data, id, childrenGenerator))
   }

   override fun add(element: LinkTreeBuilder.Element<T>) {
       elements.add(element)
   }
}